<template>
	<view class="pageContainer">
		<view class="question-type">
			<view class="question-type-text">
				<uni-icons type="checkbox-filled" size="17" color="#06BC58" style="margin-right: 2px;"></uni-icons>
				答对 <text><text style="color: #06BC58;font-size: 15px;margin: 0 4px;">4</text>题</text>
			</view>
			<view class="question-type-text">
				<uni-icons type="clear" size="17" color="#FA5846" style="margin-right: 2px;"></uni-icons>
				答错 <text><text style="color: #FA5846;font-size: 15px;margin: 0 4px;">4</text>题</text>
			</view>
			<view class="question-type-text">
				<uni-icons type="circle-filled" size="17" color="#5E6D82" style="margin-right: 2px;"></uni-icons>
				未答 <text><text style="color: #5E6D82;font-size: 15px;margin: 0 4px;">4</text>题</text>
			</view>
		</view>
		<view class="swiper-mode">
			<swiper :current="subjectIndex" class="swiper-box" @change="SwiperChange">
				<swiper-item v-for="(subject,index) in subjectList">
					<scroll-view scroll-y="true" class="swiper-content">
						<view class="swiper-content-item">
							<view class="tag-mode">
								<uni-tag :text="questionType[subject.type].text"
									custom-style="background-color: #EBF1FF; border-color:#EBF1FF; color: #3C6EC8;">
								</uni-tag>
								<text>{{subject.score}}分</text>
							</view>
							<view class="questionTitle-mode">
								{{subject.title}}
							</view>
							<view class="answer-mode">
								<template v-if="subject.type===0">
									<view class="answer-box" v-for="(option,indexT) in subject.optionList"
										:key="indexT">
										<view class="radio-box"
											:class="option.id == subject.userAnswer?'radio-box-in':''">{{option.id}}
										</view>
										<view class="text-box">{{option.content}}</view>
									</view>
								</template>
								<template v-if="subject.type===1">
									<view class="answer-box" v-for="(option,indexT) in subject.optionList"
										:key="indexT">
										<view class="radio-box" style="border-radius: 4px;"
											:class="subject.userAnswer.includes(option.id)?'radio-box-in':''">
											{{option.id}}
										</view>
										<view class="text-box">{{option.content}}</view>
									</view>
								</template>
								<template v-if="subject.type===2">
									<view class="answer-box" v-for="(option,indexT) in subject.optionList"
										:key="indexT">
										<view class="radio-box"
											:class="option.id == subject.userAnswer?'radio-box-in':''">
											<uni-icons :type="option.id=='Y'?'checkmarkempty':'closeempty'"
												:color="option.id == subject.userAnswer?'#ffffff':'#898EA2'"
												size="18"></uni-icons>
										</view>
										<view class="text-box">{{option.content}}</view>
									</view>
								</template>
								<template v-if="subject.type===3">
									<view class="answer-text-box">
										<!-- <uni-easyinput v-model="subject.userAnswer" 
											placeholder="请输入内容"></uni-easyinput> -->
										<uni-easyinput type="textarea" autoHeight v-model="subject.userAnswer"
											disabled></uni-easyinput>
									</view>
								</template>
								<template v-if="subject.type===4">
									<view class="answer-text-box">
										<uni-easyinput type="textarea" autoHeight v-model="subject.userAnswer"
											disabled></uni-easyinput>
									</view>
								</template>
							</view>
							<view class="analysis-mode" v-show="[0,1,2].includes(subject.type)">
								<view class="analysis-box-answer">
									<view class="analysis-box-answer-text">正确答案：<text style="font-size: 16px;color: #06BC58;">B</text></view>
									<view class="analysis-box-answer-text" style="margin-left: 40px;">我的答案：<text style="font-size: 16px;color: #FA5846;">A</text> </view>
								</view>
								<view class="analysis-box-content">
									<uni-section class="mb-10" title="答案解析" type="line"></uni-section>
									<view class="analysis-box-content-text">
										因为计划时间无法完整正确的路线，而
										通过回溯或整合内容可以实现内容的整理与应用分
										析数据结构解析。
									</view>
								</view>
							</view>
							<view class="analysis-mode" v-show="[3,4].includes(subject.type)">
								<view class="analysis-box-content" style="margin-top: 0;">
									<uni-section class="mb-10" title="我的作答" type="line"></uni-section>
									<view class="analysis-box-content-text">
										因为计划时间无法完整正确的路线，而
										通过回溯或整合内容可以实现内容的整理与应用分
										析数据结构解析。
									</view>
								</view>
								<view class="analysis-box-content">
									<uni-section class="mb-10" title="参考答案" type="line"></uni-section>
									<view class="analysis-box-content-text">
										因为计划时间无法完整正确的路线，而
										通过回溯或整合内容可以实现内容的整理与应用分
										析数据结构解析。
									</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
			</swiper-mode>
		</view>
		<view class="bottom-mode">
			<view class="operation-box" @click="toggle('bottom')">
				<view class="operation-box-icon">
					<image src="../../../../../static/examinationImg/detail/answerSheet.png"></image>
				</view>
				<view class="operation-box-text">答题卡</view>
			</view>
			<view class="bottom-box">
				<button class="button-box" style="margin-right: 12px;" type="primary" plain="true"
					:disabled="subjectIndex==0||subjectList.length==1"
					@click="questionSelectOp('previous')">上一题</button>
				<button class="button-box" type="primary" plain="true"
					:disabled="(subjectIndex == subjectList.length - 1)||subjectList.length==1"
					@click="questionSelectOp('next')">下一题</button>
			</view>
		</view>
		<uni-popup ref="answerSheetpopup" :is-mask-click="false">
			<view class="popup-mode">
				<view class="header-mode">
					<text style="width: 24px;"></text>
					<view class="header-box">
						<text style="font-size:16px;color: #000;font-weight: 600;">答题卡</text>
					</view>
					<uni-icons type="closeempty" size="24" @click="cancel()"></uni-icons>
				</view>
				<scroll-view class="popup-content" scroll-y="true">
					<view class="popup-content-item">
						<view class="popup-content-box" v-for="(questionItem,questionIndex) in questionType"
							:key="questionIndex" v-if="questionItem.questionList.length>0">
							<view class="popup-content-box-title">{{questionItem.text}}</view>
							<view class="popup-content-box-main">
								<view class="popup-radio-mode" v-for="(itemH,indexH) in questionItem.questionList"
									:key="indexH">
									<view class="popup-radio-box"
										:class="[itemH.userAnswer.length===0?'':'popup-radio-box-in']"
										@click="appointedSubject(itemH.currentIndex)">
										{{itemH.currentIndex+1}}
									</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentType: 0, //当前题型
				subjectIndex: 0, //跳转索引
				alertText: '确认要交卷吗?',
				subjectList: [{
						'id': '216378162783',
						"title": "电流分有？",
						"type": 0,
						'typeName': '单选题',
						'score': 3,
						"optionList": [{
							"id": "A",
							"content": "直流"
						}, {
							"id": "B",
							"content": "交流"
						}, {
							"id": "C",
							"content": "直流和交流"
						}],
						"userAnswer": "",
					},
					{
						'id': '34345345345345',
						"title": "酸菜鱼的味道？",
						"type": 1,
						'typeName': '多选题',
						'score': 6,
						"optionList": [{
							"id": "A",
							"content": "咸味",
							"cheak": false
						}, {
							"id": "B",
							"content": "辣味",
							"cheak": false
						}, {
							"id": "C",
							"content": "甜味",
							"cheak": false
						}, {
							"id": "D",
							"content": "酸味",
							"cheak": false
						}],
						"userAnswer": [],
					}, {
						'id': '34345345345345',
						"title": "水是液体？",
						'typeName': '判断题',
						"type": 2,
						'score': 3,
						"optionList": [{
							"id": "Y",
							"content": "正确"
						}, {
							"id": "N",
							"content": "错误"
						}],
						"userAnswer": "",
					},
					{
						'id': '34345345345345',
						"title": "床前（____）光，疑是地上霜。",
						"type": 3,
						'typeName': '填空题',
						'score': 5,
						"userAnswer": "",
					},
					{
						'id': '34345345345345',
						"title": "什么美国要限制华为？",
						"type": 4,
						'typeName': '问答题',
						'score': 8,
						"userAnswer": "",
					}
				],
				questionType: [{
						type: 0,
						text: "单选题",
						questionList: []
					},
					{
						type: 1,
						text: "多选题",
						questionList: []
					},
					{
						type: 2,
						text: "判断题",
						questionList: []
					},
					{
						type: 3,
						text: "填空题",
						questionList: []
					},
					{
						type: 4,
						text: "问答题",
						questionList: []
					}
				],
				//已答题目
				answeredNum: 0

			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: "2025年度职业人员综合测评考试A卷"
			})
		},
		onLoad() {},
		methods: {
			//题型分类
			questionClassificationOp() {
				this.answeredNum = 0;
				this.questionType.forEach(e => {
					e.questionList = []
				})
				this.subjectList.forEach((e, i) => {
					this.questionType.forEach(e2 => {
						if (e.type === e2.type) {
							e2.questionList.push({
								id: e.id,
								userAnswer: e.userAnswer,
								currentIndex: i
							})
						}
					})
					if (e.userAnswer.length !== 0) {
						this.answeredNum += 1;
					}
				})
				console.log(this.questionType);
			},
			//考试时间停止
			timeup() {
				this.$refs.dateDialog.open();
			},
			//答题卡
			toggle(type) {
				this.questionClassificationOp();
				// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
				this.$refs.answerSheetpopup.open(type)
			},
			//题卡指定
			appointedSubject(e) {
				this.subjectIndex = e;
				this.$refs.answerSheetpopup.close()
			},
			//关闭窗口
			cancel() {
				this.$refs.answerSheetpopup.close()
			},
			//题目选择 previous上一题 next下一题
			questionSelectOp(type) {
				if (type == 'previous') {
					this.subjectIndex -= 1;
				} else if (type == 'next') {
					this.subjectIndex += 1;
				}

			},
			//滑动事件
			SwiperChange(e) {
				let index = e.target.current;
				if (index != undefined) {
					this.subjectIndex = index;
					this.currentType = this.subjectList[index].type;
				}
			},
			//跳转
			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pageContainer {
		width: 100vw;
		height: 100vh;
	}
	.question-type {
		width: 100%;
		height: 42px;
		background-color: #ffffff;
		padding: 0 18px;
		box-sizing: border-box;
		align-items: center;
		justify-content: flex-end;
		display: flex;
		margin-bottom: 10px;
		
		.question-type-text{
			font-size: 13px;
			color: #898EA1;
			margin-left: 18px;
			align-items: center;
			display: flex;
		}
	
	}
	.operation-box {
		align-items: center;
		display: flex;
	
		.operation-box-icon {
			width: 14px;
			height: 16px;
			margin-right: 8px;
	
			image {
				width: 100%;
				height: 100%;
				background-size: 100% 100%;
			}
		}
	
		.operation-box-text {
			font-size: 14px;
			color: #333333;
		}
	}

	.swiper-mode {
		width: 100%;
		height: calc(100% - 108px);
		background-color: #FFFFFF;

		.swiper-box {
			width: 100%;
			height: 100%;

			.swiper-content {
				width: 100%;
				height: 100%;

				.swiper-content-item {
					width: 100%;
					padding: 14px 14px 30px;
					box-sizing: border-box;
				}
			}
		}
	}

	.tag-mode {
		width: 100%;
		height: 20px;
		font-size: 13px;
		color: #6B6F75;
		align-items: center;
		justify-content: space-between;
		display: flex;
		margin-bottom: 14px;
	}

	.questionTitle-mode {
		width: 100%;
		line-height: 26px;
		font-size: 15px;
		color: #000000;
	}

	.answer-mode {
		width: 100%;
		margin-top: 25px;

		.answer-box {
			width: 100%;
			display: flex;
			margin-bottom: 20px;

			.radio-box {
				width: 36px;
				height: 36px;
				font-size: 15px;
				font-weight: bold;
				color: #898EA2;
				border-radius: 100px;
				border: 1.5px solid #F0F1F5;
				box-sizing: border-box;
				align-items: center;
				justify-content: center;
				display: flex;
				margin-right: 18px;
			}

			.radio-box-in {
				color: #ffffff;
				background-color: #0080F8;
				border: 1.5px solid #0080F8;
			}

			.text-box {
				width: calc(100% - 54px);
				line-height: 26px;
				font-size: 15px;
				color: #000000;
				align-items: center;
				display: flex;
			}
		}

		//文本
		.answer-text-box {
			width: 100%;
			position: relative;

			.text-num {
				position: absolute;
				right: 10px;
				bottom: 4px;
				font-size: 12px;
				color: #9EA1A3;
			}
		}
	}
	
	.analysis-mode{
		width: 100%;
		padding: 25px 0;
		border-top: 1px solid #F0F0F0;
		box-sizing: border-box;
		margin-top: 30px;
		
		.analysis-box-answer{
			width: 100%;
			height: 52px;
			border-radius: 6px;
			background-color: #F7F8FA;
			padding: 10px 20px;
			box-sizing: border-box;
			align-items: center;
			display: flex;
			.analysis-box-answer-text{
				font-size: 14px;
				color: #898EA1;
			}
		}
		.analysis-box-content{
			width: 100%;
			margin-top: 20px;
			.analysis-box-content-text{
				width: 100%;
				line-height: 26px;
				font-size: 15px;
				color: #000;
				margin-top: 14px;
			}
			::v-deep {
				.uni-section {
					margin-top: 0;
				}
				.uni-section-header {
					padding: 0;
				}
				.uni-section__content-title{
					font-size: 15px;
					font-weight: 600;
				}
			}
		}
	}

	.bottom-mode {
		width: 100%;
		height: 56px;
		padding: 0 20px;
		box-sizing: border-box;
		background-color: #fff;
		border-top: 1px solid #E6E6E6;
		align-items: center;
		justify-content: space-between;
		display: flex;

		.bottom-box {
			align-items: center;
			display: flex;

			.button-box {
				width: 94px;
				height: 36px;
				font-size: 15px;
				border-radius: 100px;
				box-sizing: border-box;
				align-items: center;
				justify-content: center;
				display: flex;
			}
		}
	}

	/* 筛选弹出层 */
	.popup-mode {
		width: 100%;
		height: 60vh;
		background-color: #FFFFFF;
		border-radius: 12px 12px 0 0;

		.header-mode {
			width: 100%;
			height: 50px;
			border-radius: 12px 12px 0 0;
			border-bottom: 1px solid #E6E6E6;
			padding: 0 16px;
			box-sizing: border-box;
			align-items: center;
			justify-content: space-between;
			display: flex;

			.header-box {
				font-size: 13px;
				color: #6B6F75;
				align-items: center;
				display: flex;
			}
		}

		.popup-content {
			width: 100%;
			height: calc(100% - 50px);

			.popup-content-item {
				width: 100%;
				padding: 10px 16px;
				box-sizing: border-box;

				.popup-content-box {
					width: 100%;
					margin-bottom: 16px;

					.popup-content-box-title {
						width: 100%;
						font-size: 15px;
						color: #8e8e8f;
						margin-bottom: 14px;
					}

					.popup-content-box-main {
						width: 100%;
						display: flex;
						flex-wrap: wrap;

						.popup-radio-mode {
							width: calc(100%/6);

							.popup-radio-box {
								width: 36px;
								height: 36px;
								font-size: 14px;
								font-weight: 500;
								color: #000000;
								border-radius: 100px;
								background-color: #f4f5f6;
								box-sizing: border-box;
								align-items: center;
								justify-content: center;
								display: flex;
								margin: 10px;
							}

							.popup-radio-box-in {
								color: #ffffff;
								background-color: #0080F8;
								border: 1.5px solid #0080F8;
							}
						}
					}
				}

			}
		}

	}
</style>